﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SMIS.Dals;
using SMIS.Entities;

namespace SMIS
{
    public partial class ModifyIncome : Form
    {
        //public string MdfName { get; set; }(【高月 2013-3-31-164149】注释掉是因为下面通过DataTable的方式传值进来的)
        public string MdfMonth { get; set; }
        public string MdfIncome { get; set; }
        public string MdfRemark { get; set; }
        public int MdfID { get; set; }

        public ModifyIncome()
        {
            InitializeComponent();
        }

        private void ModifyIncome_Load(object sender, EventArgs e)
        {
            //cboStaffName.Text = MdfName;(【高月 2013-3-31-164149】注释掉是因为下面通过DataTable的方式传值进来的)
            txtMonth.Text = MdfMonth;
            txtIncome.Text = MdfIncome;
            txtRemark.Text = MdfRemark;

            int iID = MdfID;
            DataTable dtStaffID = Dal4Income.GetSelectedStaffID(iID);
            cboStaffName.DataSource = dtStaffID;
            cboStaffName.DisplayMember = "Staff";
            cboStaffName.ValueMember = "IID";
        }

        //修改员工收入信息时需要判断月份是否发生重复
        private void button1_Click(object sender, EventArgs e)
        {
            Income income = new Income();
            income.ID = Convert.ToInt16(cboStaffName.SelectedValue);
            income.Staff = cboStaffName.Text;
            income.Month = txtMonth.Text;
            income.Incomes = txtIncome.Text;
            income.Remark = txtRemark.Text;

            if (Dal4Income.UpdateSelectedIncome(income) == true)
            {
                if (MessageBox.Show(string.Format("确定要修改员工【{0}】的收入信息？", income.Staff), "确认信息",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    MessageBox.Show(string.Format("恭喜你修改员工【{0}】的收入信息成功", income.Staff), "提示");
            }
            else
            {
                MessageBox.Show("月份重复", "提示");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
